<template>
  <div class="container">
    <div class="content">
      <div class="top">
        <h1>{{ruleInfo.textName}}</h1>
        <span><el-button type="text" @click="goLetterList">我的上访列表</el-button></span>
      </div>
      <div class="artical" v-html="ruleInfo.textContent"></div>
      <div class="bottom">
        <div class="check-rules"><el-checkbox v-model="checked">我已了解以上条约！</el-checkbox></div>
        <div class="check-rules"><el-button type="primary" @click="goLetterAdd">我要上访</el-button></div>
      </div>
    </div>
  </div>
  
</template>

<script>
import dingMixin from  '@/mixins/ding'
export default {
  data () {
    return {
      checked: true,
      ruleInfo: {},
      authority: {}
    };
  },
  components: {},
  mixins: [dingMixin],
  mounted () {
    this.getRuleInfo()
  },
  methods: {
    goLetterAdd() {
      if(!this.checked) return this.$message.error('请勾选以上条约');
      this.$router.push({ name: 'letter-add', params: { id: false, handleType: 'add' }})
    },
    goLetterList() {
      this.$router.push({ name: !this.isPC() ? 'letter-mobileList' : 'letter-list'})
    },
    async getRuleInfo() {
      let data = await this.$httpN.postB('petition/text/info');
      let arr = [];
      data[0].textContent.split('\n').forEach((item, index)=>arr.push(`<div style='margin-bottom: 20px;'><p style='margin: 0; text-indent: 2em; color: #303334;'>${item.trim()}</p></div>`));
      data[0].textContent = arr.join('');
      this.ruleInfo = data[0];
    },
  }
}
</script>

<style lang='scss' scoped>
.container {
  width: 100%;
  height: 100vh;
  background-color: #f5f5f7;
  .content {
    height: 100%;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    .top {
      text-align: right;
      h1 {
        text-align: center;
        margin: 0;
        font-size: 24px;
        line-height: 60px;
        padding-top: 20px;
      }
      span {
        max-width: 800px;
        margin: 0 auto;
        display: inline-block;
        margin-right: 40px;
        .el-button {
          font-size: 16px;
          padding: 0;
          margin-bottom: 5px;
        }
      }
    }
    .artical {
      flex: 1;
      margin: 0 auto;
      max-width: 800px;
      padding: 20px 40px;
      font-size: 18px;
      line-height: 2;
      background-color: #FFF;
    }
  }
  .bottom {
    margin-top: 40px;
    margin-bottom: 40px;
    .check-rules {
      text-align: center;
      margin-bottom: 20px;
    }
  }
}
</style>